home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / progress.vbs < prev    next >
Encoding:
Text File  |  1998-09-14  |  5.5 KB  |  165 lines

  1. '--------------------------------------------------------------------------
  2. ' Progress.vbs - Shows how to use SG Window built-in dialog resources.
  3. '
  4. ' Progres sample shows how to open and close modeless dialog box. It opens
  5. ' dialog, creates progress bar control, waits some time and than closes
  6. ' progress dialog box.
  7. '
  8. ' REMARKS:
  9. ' - dialog resource must be located in the file that can be loaded with
  10. '   Win32 LoadLibrary() function (EXE, DLL, ...) or you can use empty
  11. '   dialog template located in the SGWINDOW.DLL module. In this case
  12. '   pass empty string as a first parameter for the DoModal method and
  13. '   string "DLG_EMPTY" as a dialog template name.
  14. ' This file is part of the SG Window.
  15. ' Copyright (C) 1998 Stinga
  16. ' All rights reserved.
  17. '--------------------------------------------------------------------------
  18. option explicit
  19.  
  20. ' Messages
  21. const wm_CLOSE         = &H0010&
  22. const wm_INITDIALOG    = &H0110&
  23. const wm_COMMAND       = &H0111&
  24.  
  25. const PBM_SETRANGE     = &H0401&
  26. const PBM_SETPOS       = &H0402&
  27. const PBM_DELTAPOS     = &H0403&
  28. const PBM_SETSTEP      = &H0404&
  29. const PBM_STEPIT       = &H0405&
  30. const PBM_SETRANGE32   = &H0406&  ' lParam = high, wParam = low
  31. const PBM_GETRANGE     = &H0407&  ' wParam = return (TRUE ? low : high). lParam = PPBRANGE or NULL
  32. const PBM_GETPOS       = &H0408&
  33.  
  34. const PBS_SMOOTH              = &H0001&
  35. const PBS_VERTICAL            = &H0004&
  36.  
  37. const ws_OVERLAPPED           = &H00000000
  38. const ws_POPUP                = &H80000000
  39. const ws_CHILD                = &H40000000
  40. const ws_MINIMIZE             = &H20000000
  41. const ws_VISIBLE              = &H10000000
  42. const ws_DISABLED             = &H08000000
  43. const ws_CLIPSIBLINGS         = &H04000000
  44. const ws_CLIPCHILDREN         = &H02000000
  45. const ws_MAXIMIZE             = &H01000000
  46. const ws_CAPTION              = &H00C00000
  47. const ws_BORDER               = &H00800000
  48. const ws_DLGFRAME             = &H00400000
  49. const ws_VSCROLL              = &H00200000
  50. const ws_HSCROLL              = &H00100000
  51. const ws_SYSMENU              = &H00080000
  52. const ws_THICKFRAME           = &H00040000
  53. const ws_GROUP                = &H00020000
  54. const ws_TABSTOP              = &H00010000
  55. const ws_MINIMIZEBOX          = &H00020000
  56. const ws_MAXIMIZEBOX          = &H00010000
  57. const ws_TILED                = &H00000000
  58. const ws_ICONIC               = &H20000000
  59. const ws_SIZEBOX              = &H00040000
  60.  
  61. const sMsg = "VBScript is working "
  62.  
  63. ' Global declarations
  64. Dim g, dlg, wProgress, wStatic, i, rc, bCanceled
  65. Set g         = WScript.CreateObject("SGWindow.Globals")
  66. Set dlg       = WScript.CreateObject("SGWindow.Window", "dlg_")
  67. Set wProgress = WScript.CreateObject("SGWindow.Window") 
  68. Set wStatic   = WScript.CreateObject("SGWindow.Window") 
  69.  
  70. ' Show dialog
  71. ' Note that empty string as a resource module instructs 
  72. ' SGWindow to use it's internal dialog resources.
  73. dlg.DoModeless "", "DLG_EMPTY", 100, 100
  74.  
  75. ' Do something
  76. bCanceled = false
  77. for i = 0 to 1000 step 10
  78.  
  79.    ' Use Sleep method to give dialog box a chance to handle
  80.    ' it's messages. Note that second parameter (true) 
  81.    ' instructs SGWindow to dispatch messages and events during 
  82.    ' sleep period.
  83.    g.Sleep 20, true
  84.    
  85.    ' Update progress bar
  86.    wProgress.SendMessage PBM_SETPOS, i, 0
  87.    wStatic.Text = sMsg & CStr(i) & "/1000"
  88.    if bCanceled Then 
  89.       MsgBox "Canceling at " & CStr(i) & "/1000"
  90.       Exit For
  91.    end if
  92. next
  93.  
  94. ' Release objects
  95. Wscript.DisconnectObject dlg
  96. dlg.Destroy
  97. Set dlg = Nothing
  98. Set wProgress = Nothing
  99. Set wStatic = Nothing
  100. Set g = Nothing
  101.  
  102. WScript.Quit
  103.  
  104. '--------------------------------------------------------------------------
  105. ' Dialog window procedure
  106. '--------------------------------------------------------------------------
  107. Sub dlg_Message(msg, wParam, lParam, result)
  108.    result = 0
  109.    select case msg
  110.      case wm_INITDIALOG
  111.         ' Initialize and position dialog
  112.         dlg.Text = "WSH Modeless Progress Bar"
  113.         dlg.SetPosition 300, 300, 400, 150
  114.         
  115.         ' Create progress bar
  116.         wProgress.Create "msctls_progress32", "", WS_CHILD + WS_VISIBLE + PBS_SMOOTH, 0, _
  117.                          20, 20, dlg.Width-45, 25, dlg.hWnd, 100
  118.         wProgress.SendMessage PBM_SETRANGE, 0, g.MakeLong(0, 1000)
  119.         
  120.         ' Create label
  121.         wStatic.Create "STATIC", sMsg, WS_CHILD + WS_VISIBLE, 0, _
  122.                        20, 50, 255, 25, dlg.hWnd, 101
  123.      
  124.         ' Create CANCEL button
  125.         Dim w
  126.         Set w = WScript.CreateObject("SGWindow.Window") 
  127.         w.Create "BUTTON", "Cancel", WS_CHILD + WS_VISIBLE + WS_TABSTOP, 0, _
  128.                  dlg.Width/2-50, dlg.Height-60, 100, 30, dlg.hWnd, 2
  129.         w.hFont = dlg.hFont
  130.         w.SetFocus
  131.                        
  132.      case wm_CLOSE
  133.             bCanceled = True
  134.         
  135.      case wm_COMMAND
  136.         Dim bHandled
  137.         bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam)
  138.         if Not bHandled Then 
  139.            result = dlg.CallWindowProc(msg, wParam, lParam)
  140.         end if
  141.      
  142.      case else
  143.         result = dlg.CallWindowProc(msg, wParam, lParam)
  144.    end select
  145. End Sub
  146.  
  147. '--------------------------------------------------------------------------
  148. ' Handle dialog WM_COMMAND messages
  149. '--------------------------------------------------------------------------
  150. Private Function OnCommand(notifyCode, id, hwnd)
  151.    OnCommand = false
  152.    select case id
  153.       case 1 ' OK
  154.            'OnCommand = True
  155.           
  156.       case 2 ' CANCEL
  157.             bCanceled = True
  158.            OnCommand = True
  159.           
  160.    end select
  161. End Function
  162.  
  163.